<?php

namespace App\Http\Controllers\Home;

use App\Http\Controllers\Controller;
use App\Models\Banner;
use App\Models\Category;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class HomeController extends Controller
{
    public function index()
    {
        $banners = Banner::query()->where('status', 1)
            ->select('id', 'title', 'image')
            ->orderBy('sort', 'asc')
            ->latest('id')
            ->limit(3)
            ->get()->toArray();
        $category = Category::query()->select('id', 'name', 'icon')
            ->where('type', 1)
            ->where('status', 1)
            ->whereNull('parent_id')
            ->orderBy('sort', 'asc')
            ->get()->toArray();

        return apiResponse(data: [
            'banners' => $banners,
            'category' => $category
        ]);
    }
}
